
cc.Class({
    extends: cc.Component,

    properties: {
        player: cc.Node,
        robot: cc.Node,
    },

    // onLoad () {},

    start() {
        this.speed = cc.v2(0, 10);
        
    },

    onBeginContact: function (contact, selfCollider, otherCollider) {
        if (otherCollider.tag === 88) {
            this.tracking();
            
            
        }
    },

    tracking() {
        let pos1 = this.robot.convertToWorldSpaceAR(cc.v2(0, 0));
        let pos2 = this.player.convertToWorldSpaceAR(cc.v2(0, 0));
        let pos = pos2.sub(pos1);
        let v = pos.normalize().mul(5);
        // this.robot.x += pos.x;
        // this.robot.y += pos.y;
        console.log(pos)
        let active = cc.moveBy(1,cc.v2(pos.x,pos.y));
        this.robot.runAction(
            active,
        )
        let angle = Math.atan(v.x / v.y) / Math.PI * 180;
        //this.robot.rotation = angle;
    },

    //update(dt) {},

});
